﻿@model HS.Presentation.Web.Models.DropDownListVM
@using System.Web.Mvc;
@{
    <script type="text/javascript">
        var ds;
        $(document).ready(function () {
            
            @*ds  = new kendo.data.DataSource({
                schema: { data: 'Data' },
                //serverFiltering: @(Model.ServerFilter==true?"true":"false"),
                async: false,
                transport: {
                    read: {
                        url: "@(Model.UrlAction)",
                        dataType: "json",
                        type: "POST",
                        data: @(String.IsNullOrEmpty(Model.Data) ? "{}": Model.Data)
                        }
                }
            
            });*@

            @*var data = AjaxObjectActionPost("@(Model.UrlAction)", @(String.IsNullOrEmpty(Model.Data) ? "{}": Model.Data));*@

            $("#@(Model.Name)").kendoDropDownList({
                @(new HtmlString(!String.IsNullOrEmpty(Model.CascadeFrom)?"autoBind: false,cascadeFrom: '"+Model.CascadeFrom+"',":""))
                optionLabel: "@(Model.Label)",
                dataTextField: "@(Model.Text)",
                dataValueField: "@(Model.Value)",
                dataSource: data@*{
                    schema: { data: 'Data' },
                    //serverFiltering: @(Model.ServerFilter==true?"true":"false"),
                    async: false,
                    transport: {
                        read: {
                            url: "@(Model.UrlAction)",
                            dataType: "json",
                            type: "POST",
                            data: @(String.IsNullOrEmpty(Model.Data) ? "{}": Model.Data)
                        }
                    }
                }*@,

                cascade: function (e) {
                    
                    if ("@(Model.UrlActionTo)" != "") { 
                        $("#@(Model.CascadeTo)").data("kendoDropDownList").options.dataSource.transport.read.data = @(String.IsNullOrEmpty(Model.DataTo) ? "{}": Model.DataTo);
                        $("#@(Model.CascadeTo)").data("kendoDropDownList").options.dataSource.transport.read.url = "@(Model.UrlActionTo)";
                    }

                    if ("@(Model.CascadeTo)" != "") {
                        $("#@(Model.CascadeTo)").data("kendoDropDownList").text("@(Model.Label)");
                        $("#@(Model.CascadeTo)").data("kendoDropDownList").value("");
                    }

                    @*if ("@(Model.UrlActionTwo)" != "") {
                        $("#@(Model.CascadeTwo)").data("kendoDropDownList").options.dataSource.transport.read.data = @(String.IsNullOrEmpty(Model.DataTwo) ? "{}": Model.DataTwo);
                        $("#@(Model.CascadeTwo)").data("kendoDropDownList").options.dataSource.transport.read.url = "@(Model.UrlActionTwo)";
                    }

                    if ("@(Model.CascadeTwo)" != "") {
                        $("#@(Model.CascadeTwo)").data("kendoDropDownList").text("@(Model.Label)");
                        $("#@(Model.CascadeTwo)").data("kendoDropDownList").value("");
                    }*@
                }
            }).data("kendoDropDownList");
        });
        </script>
}
<input id="@(Model.Name)" style="width: @(Model.Width);" name="@(Model.Name)" data-bind="@(Model.DataBind)" data-text-field="@(Model.Text)" data-value-field="@(Model.Value)" />